package com.example.administrator.School.fragment;


import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import com.bumptech.glide.Glide;
import com.example.administrator.School.KcbActivity;
import com.example.administrator.School.MainActivity;
import com.example.administrator.School.R;
import com.example.administrator.School.indicator.ZoomIndicator;
import com.example.administrator.School.until.BannerViewPager;
import com.example.administrator.School.until.BaseFragment;
import com.example.administrator.School.until.GlideImageLoader;
import com.example.administrator.School.until.PageBean;
import com.example.administrator.School.until.PageHelperListener;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

import butterknife.OnClick;

/**
 * 课程表的fragment
 */
public class thirdFragment extends BaseFragment {
    private TextSwitcher textSwitcher;
    String[] string = new String[]{
            "高数",
            "概率论",
            "网络"
    };
    // 图片数组
    private int[] arrayPictures = { R.drawable.ic_launcher, R.drawable.touxiang,
            R.drawable.touxiang, R.drawable.touxiang };
    // 要显示的图片在图片数组中的Index
    private int pictureIndex;
    // 左右滑动时手指按下的X坐标
    private float touchDownX;
    // 左右滑动时手指松开的X坐标
    private float touchUpX;

    private static final int[] RESID = {
            R.drawable.tx,
            R.drawable.tx,
            R.drawable.tx,
    };

    List<String> images=new ArrayList<>();
    List<String> titles=new ArrayList<>();//定义图片集合

    private static final String[] TEXT = {"图像处理", "LSB开发", "游戏开发"};

    int curStr ;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            next(null);
        }
    };

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_iv;
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
//        imageSwicher = (ImageSwitcher) root.findViewById(R.id.imageSwitcher);
//        // 为ImageSwicher设置Factory，用来为ImageSwicher制造ImageView
//        imageSwicher.setFactory(this);
//        // 设置ImageSwitcher左右滑动事件
//        imageSwicher.setOnTouchListener(this);

        images.add("http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg");
        images.add("http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg");
        images.add("http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg");  //图片路径

        Banner banner = (Banner) root.findViewById(R.id.banner);
        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());

        banner.setDelayTime(3000);//滚动时间
        //设置图片集合
        banner.setImages(images);
        //banner设置方法全部调用完毕时最后调用
        banner.start();


        //text切换
        textSwitcher = (TextSwitcher) root.findViewById(R.id.textSwitcher);
        textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView textView = new TextView(getContext());
                textView.setTextSize(10);
                textView.setTextColor(Color.BLACK);
                return textView;
            }
        });
        new Thread(){
            @Override
            public void run() {
                while (true){
                    Message message = handler.obtainMessage();
                    message.obj = 0;
                    handler.sendMessage(message);
                    try {
                        sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
    }
    private void next(View scource){
        textSwitcher.setText(string[curStr = ( curStr++ % string.length )]);
    }
    //进入课程表详情页面
//    @OnClick(R.id.detail)
//    void detail(){
//        startActivity(new Intent(getContext(), KcbActivity.class));
//    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
